package cn.xxstudy.visitshop.base.activity

import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingComponent
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import kotlinx.android.synthetic.main.include_toolbar.*

/**
 * @author ：DELL on 2021/3/25 .
 * @packages ：cn.xxstudy.visitshop.base.activity .
 * TODO:一句话描述
 */
abstract class BaseActivity<T : ViewDataBinding> : AppCompatActivity() {
    abstract val layoutId: Int

    abstract fun loadData(savedInstanceState: Bundle?)

    abstract val title: String

    lateinit var binding: ViewDataBinding

    open fun initView() {
        toolbarTitle.text = title
        setSupportActionBar(toolBar)
        supportActionBar?.setDisplayShowTitleEnabled(false)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView<T>(
            this,
            layoutId
        )
        initView()
        loadData(savedInstanceState)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == android.R.id.home) {
            finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }
}